{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "dff4872f",
   "metadata": {},
   "source": [
    "## 1. APP 币本位合约行情-交易规则信息函数总览"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b34b4158",
   "metadata": {},
   "source": [
    "|方法|解释|\n",
    "|:---|:---|\n",
    "|get_exchangeInfo|以缓存的方式获取一个产品的交易规则与交易对|\n",
    "|get_exchangeInfos|以缓存的方式获取全部产品的交易规则与交易对|\n",
    "|get_symbols_trading_on|获取可以交易的产品列表|\n",
    "|get_symbols_trading_off|获取不可交易的产品列表|\n",
    "|get_symbols_all|获取全部的产品列表|"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "12665560",
   "metadata": {},
   "source": [
    "## 2. 模型实例化"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "06f9778c",
   "metadata": {},
   "outputs": [],
   "source": [
    "from binance_interface.app import BinanceCM\n",
    "from binance_interface.app.utils import eprint"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "52d1c920",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 转发：需搭建转发服务器，可参考：https://github.com/pyted/binance_resender\n",
    "proxy_host = None\n",
    "key = 'xxxx'\n",
    "secret = 'xxxx'\n",
    "\n",
    "binanceCM = BinanceCM(\n",
    "    key=key, secret=secret,\n",
    "    proxy_host=proxy_host\n",
    ")\n",
    "market = binanceCM.market"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "912fbda9",
   "metadata": {},
   "source": [
    "## 3. 以缓存的方式获取一个产品的交易规则与交易对 get_exchangeInfo"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "68733c7c",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'code': 200,\n",
      " 'data': {'symbol': 'BTCUSD_PERP',\n",
      "          'pair': 'BTCUSD',\n",
      "          'contractType': 'PERPETUAL',\n",
      "          'deliveryDate': 4133404800000,\n",
      "          'onboardDate': 1597042800000,\n",
      "          'contractStatus': 'TRADING',\n",
      "          'contractSize': 100,\n",
      "          'marginAsset': 'BTC',\n",
      "          'maintMarginPercent': '2.5000',\n",
      "          'requiredMarginPercent': '5.0000',\n",
      "          'baseAsset': 'BTC',\n",
      "          'quoteAsset': 'USD',\n",
      "          'pricePrecision': 1,\n",
      "          'quantityPrecision': 0,\n",
      "          'baseAssetPrecision': 8,\n",
      "          'quotePrecision': 8,\n",
      "          'equalQtyPrecision': 4,\n",
      "          'maxMoveOrderLimit': 10000,\n",
      "          'triggerProtect': '0.0500',\n",
      "          'underlyingType': 'COIN',\n",
      "          'underlyingSubType': ['PoW'],\n",
      "          'filters': [{'minPrice': '1000', 'maxPrice': '4520958', 'filterType': 'PRICE_FILTER', 'tickSize': '0.1'},\n",
      "                      {'stepSize': '1', 'filterType': 'LOT_SIZE', 'maxQty': '1000000', 'minQty': '1'},\n",
      "                      {'stepSize': '1', 'filterType': 'MARKET_LOT_SIZE', 'maxQty': '60000', 'minQty': '1'},\n",
      "                      {'limit': 200, 'filterType': 'MAX_NUM_ORDERS'},\n",
      "                      {'limit': 20, 'filterType': 'MAX_NUM_ALGO_ORDERS'},\n",
      "                      '......'],\n",
      "          'orderTypes': ['LIMIT', 'MARKET', 'STOP', 'STOP_MARKET', 'TAKE_PROFIT', '......'],\n",
      "          'timeInForce': ['GTC', 'IOC', 'FOK', 'GTX'],\n",
      "          'liquidationFee': '0.015000',\n",
      "          'marketTakeBound': '0.05',\n",
      "          'filter': {'PRICE_FILTER': {'minPrice': '1000',\n",
      "                                      'maxPrice': '4520958',\n",
      "                                      'filterType': 'PRICE_FILTER',\n",
      "                                      'tickSize': '0.1'},\n",
      "                     'LOT_SIZE': {'stepSize': '1', 'filterType': 'LOT_SIZE', 'maxQty': '1000000', 'minQty': '1'},\n",
      "                     'MARKET_LOT_SIZE': {'stepSize': '1',\n",
      "                                         'filterType': 'MARKET_LOT_SIZE',\n",
      "                                         'maxQty': '60000',\n",
      "                                         'minQty': '1'},\n",
      "                     'MAX_NUM_ORDERS': {'limit': 200, 'filterType': 'MAX_NUM_ORDERS'},\n",
      "                     'MAX_NUM_ALGO_ORDERS': {'limit': 20, 'filterType': 'MAX_NUM_ALGO_ORDERS'},\n",
      "                     '...': '......'}},\n",
      " 'msg': ''}\n"
     ]
    }
   ],
   "source": [
    "exchangeInfo_result = market.get_exchangeInfo(symbol='BTCUSD_PERP')\n",
    "eprint(exchangeInfo_result)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "985434af",
   "metadata": {},
   "source": [
    "## 4. 以缓存的方式获取全部产品的交易规则与交易对 get_exchangeInfos"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "ec7f47dc",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'code': 200,\n",
      " 'data': {'timezone': 'UTC',\n",
      "          'serverTime': 1706191210908,\n",
      "          'rateLimits': [{'rateLimitType': 'REQUEST_WEIGHT', 'interval': 'MINUTE', 'intervalNum': 1, 'limit': 2400},\n",
      "                         {'rateLimitType': 'ORDERS', 'interval': 'MINUTE', 'intervalNum': 1, 'limit': 1200}],\n",
      "          'exchangeFilters': [],\n",
      "          'symbols': [{'symbol': 'BTCUSD_PERP',\n",
      "                       'pair': 'BTCUSD',\n",
      "                       'contractType': 'PERPETUAL',\n",
      "                       'deliveryDate': 4133404800000,\n",
      "                       'onboardDate': 1597042800000,\n",
      "                       '...': '......'},\n",
      "                      {'symbol': 'BTCUSD_240329',\n",
      "                       'pair': 'BTCUSD',\n",
      "                       'contractType': 'CURRENT_QUARTER',\n",
      "                       'deliveryDate': 1711699200000,\n",
      "                       'onboardDate': 1695974400000,\n",
      "                       '...': '......'},\n",
      "                      {'symbol': 'BTCUSD_240628',\n",
      "                       'pair': 'BTCUSD',\n",
      "                       'contractType': 'NEXT_QUARTER',\n",
      "                       'deliveryDate': 1719561600000,\n",
      "                       'onboardDate': 1703836800000,\n",
      "                       '...': '......'},\n",
      "                      {'symbol': 'ETHUSD_PERP',\n",
      "                       'pair': 'ETHUSD',\n",
      "                       'contractType': 'PERPETUAL',\n",
      "                       'deliveryDate': 4133404800000,\n",
      "                       'onboardDate': 1597734000000,\n",
      "                       '...': '......'},\n",
      "                      {'symbol': 'ETHUSD_240329',\n",
      "                       'pair': 'ETHUSD',\n",
      "                       'contractType': 'CURRENT_QUARTER',\n",
      "                       'deliveryDate': 1711699200000,\n",
      "                       'onboardDate': 1695974400000,\n",
      "                       '...': '......'},\n",
      "                      '......']},\n",
      " 'msg': ''}\n"
     ]
    }
   ],
   "source": [
    "exchangeInfos_result = market.get_exchangeInfos()\n",
    "eprint(exchangeInfos_result)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "dd1eaa8a",
   "metadata": {},
   "source": [
    "## 5. 获取可以交易的产品列表 get_symbols_trading_on"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "70e79ebe",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'code': 200,\n",
      " 'data': ['BTCUSD_PERP',\n",
      "          'BTCUSD_240329',\n",
      "          'BTCUSD_240628',\n",
      "          'ETHUSD_PERP',\n",
      "          'ETHUSD_240329',\n",
      "          'ETHUSD_240628',\n",
      "          'LINKUSD_PERP',\n",
      "          'BNBUSD_PERP',\n",
      "          'TRXUSD_PERP',\n",
      "          'DOTUSD_PERP',\n",
      "          'ADAUSD_PERP',\n",
      "          'EOSUSD_PERP',\n",
      "          'LTCUSD_PERP',\n",
      "          'BCHUSD_PERP',\n",
      "          'XRPUSD_PERP',\n",
      "          'ETCUSD_PERP',\n",
      "          'FILUSD_PERP',\n",
      "          'EGLDUSD_PERP',\n",
      "          'DOGEUSD_PERP',\n",
      "          'UNIUSD_PERP',\n",
      "          'THETAUSD_PERP',\n",
      "          'XLMUSD_PERP',\n",
      "          'SOLUSD_PERP',\n",
      "          'FTMUSD_PERP',\n",
      "          'SANDUSD_PERP',\n",
      "          'MANAUSD_PERP',\n",
      "          'AVAXUSD_PERP',\n",
      "          'MATICUSD_PERP',\n",
      "          'NEARUSD_PERP',\n",
      "          'ATOMUSD_PERP',\n",
      "          '......'],\n",
      " 'msg': ''}\n"
     ]
    }
   ],
   "source": [
    "symbols_trading_on_result = market.get_symbols_trading_on()\n",
    "eprint(symbols_trading_on_result)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9463043e",
   "metadata": {},
   "source": [
    "## 6. 获取不可交易的产品列表 get_symbols_trading_off"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "ba3ff36d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'code': 200, 'data': ['GALAUSD_PERP', 'VETUSD_PERP', 'ZILUSD_PERP'], 'msg': ''}\n"
     ]
    }
   ],
   "source": [
    "symbols_trading_off_result = market.get_symbols_trading_off()\n",
    "eprint(symbols_trading_off_result) "
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7b923da9",
   "metadata": {},
   "source": [
    "## 7. 获取全部的产品列表 get_symbols_all"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "a5a8c0d6",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'code': 200,\n",
      " 'data': ['BTCUSD_PERP',\n",
      "          'BTCUSD_240329',\n",
      "          'BTCUSD_240628',\n",
      "          'ETHUSD_PERP',\n",
      "          'ETHUSD_240329',\n",
      "          'ETHUSD_240628',\n",
      "          'LINKUSD_PERP',\n",
      "          'BNBUSD_PERP',\n",
      "          'TRXUSD_PERP',\n",
      "          'DOTUSD_PERP',\n",
      "          'ADAUSD_PERP',\n",
      "          'EOSUSD_PERP',\n",
      "          'LTCUSD_PERP',\n",
      "          'BCHUSD_PERP',\n",
      "          'XRPUSD_PERP',\n",
      "          'ETCUSD_PERP',\n",
      "          'FILUSD_PERP',\n",
      "          'EGLDUSD_PERP',\n",
      "          'DOGEUSD_PERP',\n",
      "          'UNIUSD_PERP',\n",
      "          'THETAUSD_PERP',\n",
      "          'XLMUSD_PERP',\n",
      "          'SOLUSD_PERP',\n",
      "          'FTMUSD_PERP',\n",
      "          'SANDUSD_PERP',\n",
      "          'MANAUSD_PERP',\n",
      "          'AVAXUSD_PERP',\n",
      "          'GALAUSD_PERP',\n",
      "          'MATICUSD_PERP',\n",
      "          'NEARUSD_PERP',\n",
      "          '......'],\n",
      " 'msg': ''}\n"
     ]
    }
   ],
   "source": [
    "symbols_all_result = market.get_symbols_all()\n",
    "eprint(symbols_all_result)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
